
Ext.define('PackageManager.view.PackageView', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.packageview',
    title: 'Package Manager',
    store: 'ComponentStore',
    width: 500,
    id: 'griddy',
    columns: [
        {
            text: 'Label',
            dataIndex: 'label',
            tdCls: 'label',
            style: {
                fontWeight: 'bold'
            },
            id: 'label',
            flex: 3
        },
        {
            text: 'EXIST',
            dataIndex: 'existsValue',
            flex: 2,
            tdCls: 'exist',
            id: 'existColumn'
        },
        {
            text: 'FINAL',
            dataIndex: 'finalValue',
            tdCls: 'cells',
            id: 'finalColumn'
        }
    ],
    plugins: [
        Ext.create('Ext.grid.plugin.CellEditing', {
            clicksToEdit: 1
        })
    ],
    chooseState: function() {
        if (Ext.getStore('PackageStore').first() == null) {
            return false;
        }
        var dataStage = Ext.getStore('PackageStore').first().data.stage;
        var existColumn = Ext.getCmp('existColumn');
        var finalColumn = Ext.getCmp('finalColumn');
        this.setTitle('Current stage: ' + dataStage);
        if (dataStage == 'PRE_COMMITTEE') {
            existColumn.editor = this.comboPack();
            existColumn.tdCls = 'cells ' + existColumn.getEditor().getValue();
            finalColumn.hide();
        } else if (dataStage == 'IN_COMMITTEE') {
            finalColumn.show();
            existColumn.setEditor(null);
            existColumn.tdCls = '';
            finalColumn.editor = this.comboPack();
        }
        this.getView().refresh();
    },
    comboPack: function() {
        var comboEdit = new Ext.form.ComboBox({
            queryMode: 'local',
            store: 'StaticDataStore',
            cls: 'supereditor',
            pluginId: 'finalEdit',
            displayField: 'label',
            listConfig: {
                componentCls: 'editorList'
            },
            editable: false,
            listeners: {
                beforequery: function(qe) {
                    var varFilter = this.up().up().getSelectionModel().getSelection()[0].getData().staticData;
                    qe.combo.store.clearFilter(true);
                    qe.combo.store.filter([
                        {
                            filterFn: function(item) {
                                return item.get("staticDataSet") == varFilter;
                            }
                        }
                    ]);
                },
                focus: function() {
                    this.doQuery('');
                    this.expand();
                },
                select: function() {
                    this.triggerBlur();

                },
                blur: function() {
                }
            }
        });
        return comboEdit;
    }
})
;